package com.teziyou.commodity.web.jfinal;

import java.util.Date;

import com.jfinal.plugin.activerecord.Page;
import com.teziyou.commodity.constant.Global;
import com.teziyou.commodity.enumtype.ShelfStatusEnum;
import com.teziyou.commodity.model.OnSaleTicket;
import com.teziyou.commodity.model.ScenicSpot;
import com.teziyou.commodity.util.DateUtil;
import com.teziyou.commodity.util.Lang;

public class OnSaleTicketAction extends BaseController {
	
	public void index() {
		page();
		renderJsp("/WEB-INF/jsp/ticket/shelf/index.jsp");
	}
	
	public void table() {
		page();
		renderJsp("/WEB-INF/jsp/ticket/shelf/table.jsp");
	}
	
	public void page() {
		int pageNo = getParaToInt("pageNo", 1);
		String name = getPara("name");
		String launchTime = getPara("launchTime");
		String endTime = getPara("endTime");
		String startTime = getPara("startTime");
		String scenicId = getPara("scenic_id");
		int pageSize = Global.pageSize;
		Page<OnSaleTicket> page = OnSaleTicket.dao.getFullTicketByPage(scenicId, name, launchTime, startTime
				, endTime, pageNo, pageSize);
		for(OnSaleTicket ost:page.getList()) {
			long sid = ost.getLong("scenic_id");
			ScenicSpot ss = ScenicSpot.dao.findById(sid);
			ost.put("scene", ss);
			ost.put("shelf_status", ShelfStatusEnum.getEnumByCode(ost.getInt("isOK")).getDesc());
			Date ltime = ost.getDate("launch_time");
			ost.put("launch_time_display", ltime==null?"":DateUtil.formatDate(ltime, "yyyy.MM.dd"));
			Date ftime = ost.getDate("from_time");
			ost.put("from_time_display", ftime==null?"":DateUtil.formatDate(ftime, "yyyy.MM.dd"));
			Date etime = ost.getDate("end_time");
			ost.put("end_time_display", etime==null?"":DateUtil.formatDate(etime, "yyyy.MM.dd"));
			ost.put("discount_display", Lang.toString(ost.get("discount")).replace("0", ""));
		}
		
		setAttr("page", page);
	}

}
